package space.goldchen.kafka.kafka;


import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Service;
/**
 * kafka生产者
 * @author 2021
 * @create 2025-04-16 16:27
 */
@Service
@Slf4j
public class KafkaProducer {

    @Resource
    private KafkaTemplate<String, String> kafkaTemplate;

    /**
     * 发送消息
     * @param topic 主题
     * @param message 要发送的消息
     */
    public void sendMessage(String topic, String message) {
        kafkaTemplate.send(topic, message);
        // 用log.info重写下边的日志
        log.info("Message sent to topic: {}, Message:{}" , topic, message);
    }
}
